/*
 * @Description: 查看网页
 * @Author: kivet
 * @Date: 2021-03-09 15:26:03
 * @LastEditTime: 2022-01-07 11:29:32
 */

import { useState, useEffect } from 'react';
import { View, RichText } from '@tarojs/components';
import { useRouter } from '@tarojs/taro';
import { getAgrement } from './service';
import styles from './index.module.less';

const ReadAgreement = () => {
  const [textContent, setTextContent] = useState('服务协议内容未提供');

  const {
    params: { textCode = '' },
  } = useRouter();

  useEffect(() => {
    // TODO: 等待后端提供对应的文本接口
    getAgrement({
      textCode,
    }).then((res: any) => {
      if (res.textContent) setTextContent(res.textContent);
    });
  }, []);

  return (
    <View className={styles.container}>
      {textContent !== '' && (
        <View className={styles.textContet}>
          <RichText nodes={textContent} />
        </View>
      )}
    </View>
  );
};

export default ReadAgreement;
